<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><%= title %></title>

</head>

<body>
<div id="container" class="container">
    <% if (locals.success) { %>
    <div id="alt_sucess">
        <%- success %>
    </div>
    <% } %>

    <% if (locals.error) { %>
    <div id="alt_warning">
        <%= error %>
    </div>
    <% } %>

    <form  name="form1" id="form1" method="post" action="/uploading " enctype='multipart/form-data'>
        <fieldset>
            <legend><h1>添加视频</h1>
                <div>
                    <label>分类</label>
                    <div>
                        <!--<input type="text" name="videoFenlei" >-->
                        <select name="videoFenlei" type="input" autofocus="true">
                            <option value="影视">影视</option>
                            <option value="音乐">音乐</option>
                            <option value="动画">动画</option>
                            <option value="番剧">番剧</option>
                            <option value="游戏">游戏</option>
                        </select>

                    </div>
                    <label>视屏标题</label>
                    <div >
                        <input type="text" name="videoName" >
                    </div>
                    <h2 >上传文件</h2>
                    <input id="fulAvatar" name="fulAvatar" type="file" class="form-control" />
                    <br/>
                    <button type="submit">上传添加</button>
                </div>
            </legend>
        </fieldset>
    </form>

</div>
</body>
</html>

<script src="/js/jquery-2.1.4.min.js" type="text/javascript"></script>

<script type="text/javascript">
    String.prototype.format = function (args) {
        var result = this;
        if (arguments.length > 0) {
            if (arguments.length == 1 && typeof (args) == "object") {
                for (var key in args) {
                    if (args[key] != undefined) {
                        var reg = new RegExp("({" + key + "})", "g");
                        result = result.replace(reg, args[key]);
                    }
                }
            }
            else {
                for (var i = 0; i < arguments.length; i++) {
                    if (arguments[i] != undefined) {
                        var reg = new RegExp("({)" + i + "(})", "g");
                        result = result.replace(reg, arguments[i]);
                    }
                }
            }
        }
        console.log("result="+result);
        return result;
    }

    $(function(){
        $('#btnSub').on('click',function(){
            var fulAvatarVal = $('#fulAvatar').val(),
                    errorTip = '<div id="errorTip" class="alert alert-warning">{0}</div> ';


            $("#errorTip,#alt_warning").remove();

            if(fulAvatarVal.length == 0)
            {
                $("#container").prepend(errorTip.format('请选择要上传的文件'));
                return false;
            }
            console.log("待上传文件名字："+fulAvatarVal);
            $("#container").prepend(errorTip.format(fulAvatarVal));
            var extName = fulAvatarVal.substring(fulAvatarVal.lastIndexOf('.'),fulAvatarVal.length).toLowerCase();
            console.log("后缀名:"+extName+"  整体长度："+fulAvatarVal.length);
            var priName = fulAvatarVal.substring(fulAvatarVal.lastIndexOf('\\'),fulAvatarVal.length).toLowerCase();
            console.log("应该的原文件名："+priName);
            //$("#fileName").value=priName;
            $("#fileName").text(priName);
            //$("#fileName").innerHTML=priName;
           // $("#fileName").innerText=priName;
            console.log("label名："+$("#fileName").text());
            if(extName != '.mp4' && extName != '.webm'&& extName != '.ogg' &&extName!='.wmv'){
                $("#container").prepend(errorTip.format('暂时只支持mp4、webm和ogg格式视频'));
                return false;
            }
            return true;
        })
    });

</script>